package com.ithong.crm.service.impl;

import com.ithong.crm.mapper.CourseOrderMappper;
import com.ithong.crm.model.CourseOrder;
import com.ithong.crm.model.MonthIncome;
import com.ithong.crm.model.PageResult;
import com.ithong.crm.service.CourseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CourseOrderServiceImpl implements CourseOrderService {

    @Autowired
    CourseOrderMappper courseOrderMappper;

    @Override
    public PageResult<CourseOrder> findPageResult(CourseOrder condition, int page, int pageSize) {
        PageResult<CourseOrder> result = new PageResult<CourseOrder>();
        result.setCode(0);

        /**
         * 查询参数先设置为空
         */
        Map<String, Object> map = new HashMap<>();

        //获取总记录数据
        int totalcount = courseOrderMappper.findCountByMap(map);
        //select * from crm limit 0,10
        map.put("condition",condition);
        map.put("start",(page-1)*pageSize);
        map.put("pageSize",pageSize);
        result.setCount(totalcount);

        //获取查询的数据
        List<CourseOrder> list = courseOrderMappper.findListByMap(map);
        result.setData(list);
        return result;
    }

    @Override
    public int save(CourseOrder courseOrder) {
        return courseOrderMappper.insert(courseOrder);
    }

    @Override
    public int deleteById(Integer id) {
        return courseOrderMappper.delete(id);
    }

    @Override
    public int update(CourseOrder courseOrder) {
        return courseOrderMappper.update(courseOrder);
    }

    @Override
    public List<MonthIncome> getMonthIncome() {
        return courseOrderMappper.getMonthIncomes();
    }


}
